package com.doit.day03.不可变集合

object _02_数组中的方法 {
  def main(args: Array[String]): Unit = {
    //    val ints: Array[Int] = new Array[Int](5)
    val arr: Array[Int] = Array(1, 2, 3, 3, 5)
    println(arr.apply(0))
    arr.update(0, 10)
    println(arr.apply(0))
    println(arr.length)//数组的长度

    //其他的方法
    println(arr.size)

    println(arr.head)//10
    val tail: Array[Int] = arr.tail
    println(tail.mkString("_"))//2_3_4_5

    val distinct: Array[Int] = arr.distinct
    println(distinct.mkString(","))//10,2,3,5

    val ints: Array[Int] = arr.take(2)
    println(ints.mkString(","))
    val ints1: Array[Int] = arr.takeRight(2)
    println(ints1.mkString(","))//3,5


    println(arr.last)//5

    val ints2: Array[Int] = arr.drop(1)
    println(ints2.mkString(","))//2,3,3,5
    println(arr.mkString(","))//10,2,3,3,5


    val ints3: Array[Int] = arr.dropRight(2)
    println(ints3.mkString(","))//10,2,3
    println(arr.mkString(","))//10,2,3,3,5


    val ints4: Array[Int] = ints3.union(arr)
    println(ints4.mkString(","))//10,2,3,10,2,3,3,5

    val ints5: Array[Int] = arr.diff(ints3)
    println(ints5.mkString(","))//3,5

    val ints6: Array[Int] = arr.intersect(ints3)
    println(ints6.mkString(","))//10,2,3

    val ints9: Array[Int] = Array(10, 20, 30)
    val ints7: Array[Int] = arr.:+(100)//10,2,3,3,5,100
    val ints8: Array[Int] = arr.+:(100)//100,10,2,3,3,5
    val ints10: Array[Int] = arr.++(ints9)//10,2,3,3,5,10,20,30
    val ints11: Array[Int] = arr.++:(ints9)//10,20,30,10,2,3,3,5

    println(ints7.mkString(","))
    println(ints8.mkString(","))
    println(ints10.mkString(","))
    println(ints11.mkString(","))









  }
}
